package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.util.JdbcUtil;

/**
 * Servlet implementation class UpdateServlet
 */
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer pid =Integer.parseInt(request.getParameter("pid"));
    	String pname = request.getParameter("pname");
		double pprice = Double.parseDouble(request.getParameter("pprice"));
		String skids = request.getParameter("kid");
		int kid =Integer.parseInt(skids);
		String pimage = request.getParameter("pimage");
		String pdesc = request.getParameter("pdesc");
		JdbcUtil jdbc = new JdbcUtil();
		String sql = "update product set pname=?, pprice=?,kid=?,pimage=?,pdesc=? where pid="+pid;
		try {
			jdbc.updatePreparedStatement(sql,pname,pprice,kid,pimage, pdesc);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		PrintWriter out = response.getWriter();
		out.print(1);
		out.flush();
		out.close();
	}
	

}
